<?php


abstract class BaseTabDiagnosticos extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id_diagnostico;


	
	protected $nacionalidad;


	
	protected $cedula;


	
	protected $cf_historia;


	
	protected $cf_cita;


	
	protected $cf_medico;


	
	protected $fecha_diagnostico;


	
	protected $observaciones;


	
	protected $nacionalidad_med;


	
	protected $cedula_med;


	
	protected $estatus;

	
	protected $collTabDiagnosticosEnfermedadess;

	
	protected $lastTabDiagnosticosEnfermedadesCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getIdDiagnostico()
	{

		return $this->id_diagnostico;
	}

	
	public function getNacionalidad()
	{

		return $this->nacionalidad;
	}

	
	public function getCedula()
	{

		return $this->cedula;
	}

	
	public function getCfHistoria()
	{

		return $this->cf_historia;
	}

	
	public function getCfCita()
	{

		return $this->cf_cita;
	}

	
	public function getCfMedico()
	{

		return $this->cf_medico;
	}

	
	public function getFechaDiagnostico($format = 'Y-m-d')
	{

		if ($this->fecha_diagnostico === null || $this->fecha_diagnostico === '') {
			return null;
		} elseif (!is_int($this->fecha_diagnostico)) {
						$ts = strtotime($this->fecha_diagnostico);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha_diagnostico] as date/time value: " . var_export($this->fecha_diagnostico, true));
			}
		} else {
			$ts = $this->fecha_diagnostico;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getObservaciones()
	{

		return $this->observaciones;
	}

	
	public function getNacionalidadMed()
	{

		return $this->nacionalidad_med;
	}

	
	public function getCedulaMed()
	{

		return $this->cedula_med;
	}

	
	public function getEstatus()
	{

		return $this->estatus;
	}

	
	public function setIdDiagnostico($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->id_diagnostico !== $v) {
			$this->id_diagnostico = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::ID_DIAGNOSTICO;
		}

	} 
	
	public function setNacionalidad($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->nacionalidad !== $v) {
			$this->nacionalidad = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::NACIONALIDAD;
		}

	} 
	
	public function setCedula($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cedula !== $v) {
			$this->cedula = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::CEDULA;
		}

	} 
	
	public function setCfHistoria($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_historia !== $v) {
			$this->cf_historia = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::CF_HISTORIA;
		}

	} 
	
	public function setCfCita($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_cita !== $v) {
			$this->cf_cita = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::CF_CITA;
		}

	} 
	
	public function setCfMedico($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_medico !== $v) {
			$this->cf_medico = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::CF_MEDICO;
		}

	} 
	
	public function setFechaDiagnostico($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha_diagnostico] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha_diagnostico !== $ts) {
			$this->fecha_diagnostico = $ts;
			$this->modifiedColumns[] = TabDiagnosticosPeer::FECHA_DIAGNOSTICO;
		}

	} 
	
	public function setObservaciones($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->observaciones !== $v) {
			$this->observaciones = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::OBSERVACIONES;
		}

	} 
	
	public function setNacionalidadMed($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->nacionalidad_med !== $v) {
			$this->nacionalidad_med = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::NACIONALIDAD_MED;
		}

	} 
	
	public function setCedulaMed($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cedula_med !== $v) {
			$this->cedula_med = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::CEDULA_MED;
		}

	} 
	
	public function setEstatus($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->estatus !== $v) {
			$this->estatus = $v;
			$this->modifiedColumns[] = TabDiagnosticosPeer::ESTATUS;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id_diagnostico = $rs->getString($startcol + 0);

			$this->nacionalidad = $rs->getString($startcol + 1);

			$this->cedula = $rs->getString($startcol + 2);

			$this->cf_historia = $rs->getString($startcol + 3);

			$this->cf_cita = $rs->getString($startcol + 4);

			$this->cf_medico = $rs->getString($startcol + 5);

			$this->fecha_diagnostico = $rs->getDate($startcol + 6, null);

			$this->observaciones = $rs->getString($startcol + 7);

			$this->nacionalidad_med = $rs->getString($startcol + 8);

			$this->cedula_med = $rs->getString($startcol + 9);

			$this->estatus = $rs->getString($startcol + 10);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 11; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TabDiagnosticos object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabDiagnosticosPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TabDiagnosticosPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabDiagnosticosPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TabDiagnosticosPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setIdDiagnostico($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TabDiagnosticosPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collTabDiagnosticosEnfermedadess !== null) {
				foreach($this->collTabDiagnosticosEnfermedadess as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = TabDiagnosticosPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collTabDiagnosticosEnfermedadess !== null) {
					foreach($this->collTabDiagnosticosEnfermedadess as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabDiagnosticosPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getIdDiagnostico();
				break;
			case 1:
				return $this->getNacionalidad();
				break;
			case 2:
				return $this->getCedula();
				break;
			case 3:
				return $this->getCfHistoria();
				break;
			case 4:
				return $this->getCfCita();
				break;
			case 5:
				return $this->getCfMedico();
				break;
			case 6:
				return $this->getFechaDiagnostico();
				break;
			case 7:
				return $this->getObservaciones();
				break;
			case 8:
				return $this->getNacionalidadMed();
				break;
			case 9:
				return $this->getCedulaMed();
				break;
			case 10:
				return $this->getEstatus();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabDiagnosticosPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getIdDiagnostico(),
			$keys[1] => $this->getNacionalidad(),
			$keys[2] => $this->getCedula(),
			$keys[3] => $this->getCfHistoria(),
			$keys[4] => $this->getCfCita(),
			$keys[5] => $this->getCfMedico(),
			$keys[6] => $this->getFechaDiagnostico(),
			$keys[7] => $this->getObservaciones(),
			$keys[8] => $this->getNacionalidadMed(),
			$keys[9] => $this->getCedulaMed(),
			$keys[10] => $this->getEstatus(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabDiagnosticosPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setIdDiagnostico($value);
				break;
			case 1:
				$this->setNacionalidad($value);
				break;
			case 2:
				$this->setCedula($value);
				break;
			case 3:
				$this->setCfHistoria($value);
				break;
			case 4:
				$this->setCfCita($value);
				break;
			case 5:
				$this->setCfMedico($value);
				break;
			case 6:
				$this->setFechaDiagnostico($value);
				break;
			case 7:
				$this->setObservaciones($value);
				break;
			case 8:
				$this->setNacionalidadMed($value);
				break;
			case 9:
				$this->setCedulaMed($value);
				break;
			case 10:
				$this->setEstatus($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabDiagnosticosPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setIdDiagnostico($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNacionalidad($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCedula($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCfHistoria($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCfCita($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setCfMedico($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setFechaDiagnostico($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setObservaciones($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setNacionalidadMed($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCedulaMed($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setEstatus($arr[$keys[10]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TabDiagnosticosPeer::DATABASE_NAME);

		if ($this->isColumnModified(TabDiagnosticosPeer::ID_DIAGNOSTICO)) $criteria->add(TabDiagnosticosPeer::ID_DIAGNOSTICO, $this->id_diagnostico);
		if ($this->isColumnModified(TabDiagnosticosPeer::NACIONALIDAD)) $criteria->add(TabDiagnosticosPeer::NACIONALIDAD, $this->nacionalidad);
		if ($this->isColumnModified(TabDiagnosticosPeer::CEDULA)) $criteria->add(TabDiagnosticosPeer::CEDULA, $this->cedula);
		if ($this->isColumnModified(TabDiagnosticosPeer::CF_HISTORIA)) $criteria->add(TabDiagnosticosPeer::CF_HISTORIA, $this->cf_historia);
		if ($this->isColumnModified(TabDiagnosticosPeer::CF_CITA)) $criteria->add(TabDiagnosticosPeer::CF_CITA, $this->cf_cita);
		if ($this->isColumnModified(TabDiagnosticosPeer::CF_MEDICO)) $criteria->add(TabDiagnosticosPeer::CF_MEDICO, $this->cf_medico);
		if ($this->isColumnModified(TabDiagnosticosPeer::FECHA_DIAGNOSTICO)) $criteria->add(TabDiagnosticosPeer::FECHA_DIAGNOSTICO, $this->fecha_diagnostico);
		if ($this->isColumnModified(TabDiagnosticosPeer::OBSERVACIONES)) $criteria->add(TabDiagnosticosPeer::OBSERVACIONES, $this->observaciones);
		if ($this->isColumnModified(TabDiagnosticosPeer::NACIONALIDAD_MED)) $criteria->add(TabDiagnosticosPeer::NACIONALIDAD_MED, $this->nacionalidad_med);
		if ($this->isColumnModified(TabDiagnosticosPeer::CEDULA_MED)) $criteria->add(TabDiagnosticosPeer::CEDULA_MED, $this->cedula_med);
		if ($this->isColumnModified(TabDiagnosticosPeer::ESTATUS)) $criteria->add(TabDiagnosticosPeer::ESTATUS, $this->estatus);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TabDiagnosticosPeer::DATABASE_NAME);

		$criteria->add(TabDiagnosticosPeer::ID_DIAGNOSTICO, $this->id_diagnostico);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getIdDiagnostico();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setIdDiagnostico($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setNacionalidad($this->nacionalidad);

		$copyObj->setCedula($this->cedula);

		$copyObj->setCfHistoria($this->cf_historia);

		$copyObj->setCfCita($this->cf_cita);

		$copyObj->setCfMedico($this->cf_medico);

		$copyObj->setFechaDiagnostico($this->fecha_diagnostico);

		$copyObj->setObservaciones($this->observaciones);

		$copyObj->setNacionalidadMed($this->nacionalidad_med);

		$copyObj->setCedulaMed($this->cedula_med);

		$copyObj->setEstatus($this->estatus);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getTabDiagnosticosEnfermedadess() as $relObj) {
				$copyObj->addTabDiagnosticosEnfermedades($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setIdDiagnostico(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TabDiagnosticosPeer();
		}
		return self::$peer;
	}

	
	public function initTabDiagnosticosEnfermedadess()
	{
		if ($this->collTabDiagnosticosEnfermedadess === null) {
			$this->collTabDiagnosticosEnfermedadess = array();
		}
	}

	
	public function getTabDiagnosticosEnfermedadess($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTabDiagnosticosEnfermedadesPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTabDiagnosticosEnfermedadess === null) {
			if ($this->isNew()) {
			   $this->collTabDiagnosticosEnfermedadess = array();
			} else {

				$criteria->add(TabDiagnosticosEnfermedadesPeer::CF_DIAGNOSTICO, $this->getIdDiagnostico());

				TabDiagnosticosEnfermedadesPeer::addSelectColumns($criteria);
				$this->collTabDiagnosticosEnfermedadess = TabDiagnosticosEnfermedadesPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(TabDiagnosticosEnfermedadesPeer::CF_DIAGNOSTICO, $this->getIdDiagnostico());

				TabDiagnosticosEnfermedadesPeer::addSelectColumns($criteria);
				if (!isset($this->lastTabDiagnosticosEnfermedadesCriteria) || !$this->lastTabDiagnosticosEnfermedadesCriteria->equals($criteria)) {
					$this->collTabDiagnosticosEnfermedadess = TabDiagnosticosEnfermedadesPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastTabDiagnosticosEnfermedadesCriteria = $criteria;
		return $this->collTabDiagnosticosEnfermedadess;
	}

	
	public function countTabDiagnosticosEnfermedadess($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseTabDiagnosticosEnfermedadesPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(TabDiagnosticosEnfermedadesPeer::CF_DIAGNOSTICO, $this->getIdDiagnostico());

		return TabDiagnosticosEnfermedadesPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addTabDiagnosticosEnfermedades(TabDiagnosticosEnfermedades $l)
	{
		$this->collTabDiagnosticosEnfermedadess[] = $l;
		$l->setTabDiagnosticos($this);
	}


	
	public function getTabDiagnosticosEnfermedadessJoinTabEnfermedades($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseTabDiagnosticosEnfermedadesPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collTabDiagnosticosEnfermedadess === null) {
			if ($this->isNew()) {
				$this->collTabDiagnosticosEnfermedadess = array();
			} else {

				$criteria->add(TabDiagnosticosEnfermedadesPeer::CF_DIAGNOSTICO, $this->getIdDiagnostico());

				$this->collTabDiagnosticosEnfermedadess = TabDiagnosticosEnfermedadesPeer::doSelectJoinTabEnfermedades($criteria, $con);
			}
		} else {
									
			$criteria->add(TabDiagnosticosEnfermedadesPeer::CF_DIAGNOSTICO, $this->getIdDiagnostico());

			if (!isset($this->lastTabDiagnosticosEnfermedadesCriteria) || !$this->lastTabDiagnosticosEnfermedadesCriteria->equals($criteria)) {
				$this->collTabDiagnosticosEnfermedadess = TabDiagnosticosEnfermedadesPeer::doSelectJoinTabEnfermedades($criteria, $con);
			}
		}
		$this->lastTabDiagnosticosEnfermedadesCriteria = $criteria;

		return $this->collTabDiagnosticosEnfermedadess;
	}

} 